{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# 随机数生成\n",
    "import numpy as np\n",
    "from random import normalvariate"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0.09006008,  1.20423284, -0.92094943,  0.43366002],\n",
       "       [-0.15257112,  0.72909695,  1.34447948, -0.03355902],\n",
       "       [-0.86793632, -0.26153313,  0.33832876,  0.63170116],\n",
       "       [-0.42726675,  0.69468188, -0.37173825,  1.13598021]])"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "samples = np.random.normal(size=(4, 4))\n",
    "samples"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 loop, best of 3: 942 ms per loop\n",
      "10 loops, best of 3: 31.6 ms per loop\n"
     ]
    }
   ],
   "source": [
    "N = 1000000\n",
    "# 性能对比\n",
    "%timeit samples = [normalvariate(0, 1) for _ in range(N)]\n",
    "%timeit np.random.normal(size=N)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# 常用random函数\n",
    "# seed\n",
    "# permulation：返回一个序列的随机排列或返回一个随机排列的范围\n",
    "# shuffle\n",
    "# rand\n",
    "# randint：    从给定的上下限范围内随机选取整数\n",
    "# randn：      产生正态分布的样本值\n",
    "# binomial\n",
    "# normal:      产生正态（高斯）分布的样本值\n",
    "# beta\n",
    "# chisquare\n",
    "# gamme\n",
    "# uniform：    产生在[0, 1]中均匀分布的样本值"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
